package com.edu.dao.impl;

import com.edu.bean.Book;
import com.edu.dao.BaseDao;
import com.edu.dao.BookDao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class BookDaoImpl implements BookDao {
    @Override
    public List<Book> selectBookAll(){
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet res = null;
        String sql = "SELECT * FROM book";
        List<Book> list = new ArrayList<Book>();
        try {
            con = BaseDao.getConn();
            ps= con.prepareStatement(sql);
            res = ps.executeQuery();
            while(res.next()) {
				Book book=new Book();
				book.setBookId(res.getInt("bookId"));
				book.setBookName(res.getString("bookName"));
                book.setBookType(res.getString("bookType"));
                book.setBookAuthor(res.getString("bookAuthor"));
			    list.add(book);
			}
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            BaseDao.closeAll(con,ps,res);
        }
        return list;
    }
}
